import React, { Component, Suspense } from 'react';
import { Button, Modal, Table, Row, Pagination, Form, Checkbox } from 'antd';
import styles from './index.less';
import { connect } from 'dva';
const FormItem = Form.Item;
class SelectDialog extends Component {
    state = {
        selectedRows: [],
        tableData: [],
    }
    componentDidMount() {
        const { dispatch } = this.props;
        const uid = window.localStorage.getItem('uid') == undefined ? '' : window.localStorage.getItem('uid');
        this.reqRef = requestAnimationFrame(() => {
            dispatch({
                type: 'sameOperateAnalysis/robotGetRobotList',
                payload: { userId: uid },
                callback: res => {
                    if (res.code == 0) {
                        const { data: { coopertion, ownRobot } } = res;
                        let tableData = coopertion.concat(ownRobot);
                        this.setState({ tableData })
                    }
                }
            })
        })
    }
    render() {
        const { selectedRowKeys, tableData } = this.state;
        const { visible, onCancel, onConfire } = this.props;
        const operationDate = [
            {
                title: '机器人名称',
                dataIndex: 'name',
                align: 'left',
                width: 'calc(18vw)',
            },
        ];
        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
                this.setState(selectedRows);
                this.props.getRowSelect(selectedRows)
            },
        };
        return (
            <Modal
                visible={visible}
                title="筛选机器人"
                okText="确认"
                cancelText="取消"
                onCancel={onCancel}
                onOk={onConfire}
            >
                <Row>
                    <Row style={{height:350}}>
                        <Table
                            className={'robotSelect'}
                            rowSelection={rowSelection}
                            columns={operationDate}
                            dataSource={tableData}
                            pagination={false}
                            scroll={{ y: 300 }}
                        ></Table>
                    </Row>
                </Row>
            </Modal>
        )
    }
}
export default connect(({ user }) => ({
    currentUser: user.currentUser,
}))(Form.create()(SelectDialog));
